<?php
/*
  $Program: ECJC Online Shop
  $Id: wishlist_email.php
  $Based on: osCommerce, Open Source E-Commerce Solutions
  Released under the GNU General Public License
*/
  defined( 'joscom' ) or die( 'Direct Access to this location is not allowed.' );
  if (defined( '_OSCOMMERCE_LOADED' )) {
    if (!DB_SHARED) {
      tep_db_connect() or die('Unable to connect to database server!');
    }
    global $category_links, $languages_id, $catID, $catID_array, $current_category_id;
    global $request_type, $lng, $cart, $currencies, $language, $navigation, $breadcrumb;
  } else {
    require('components/'.$option.'/includes/application_top.php');
  }

  require(DIR_WS_LANGUAGES . $language . '/' . $osMod . '.php');

  if (!tep_session_is_registered('customer_id')) {
    $navigation->set_snapshot();
    tep_redirect(tep_href_link(FILENAME_LOGIN, '', 'SSL'));
  }

  require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_WISHLIST_SEND);

  $breadcrumb->add(NAVBAR_TITLE, tep_href_link(FILENAME_WISHLIST_SEND, '', 'NONSSL'));
require(DIR_WS_INCLUDES . 'header.php'); 

if (tep_session_is_registered('customer_id')) {
    $account = tep_db_query("select customers_firstname, customers_lastname, customers_email_address from " . TABLE_CUSTOMERS . " where customers_id = '" . $customer_id . "'");
    $account_values = tep_db_fetch_array($account);
  }

$wishliststring = FORM_FIELD_TEXT_AREA;
if ($wishlist->count_contents() > 0)
{
    $products = $wishlist->get_products();
    $size = sizeof($products);
    for ($i=0; $i<$size; $i++)
    {

	$wishliststring .="<ul><li> "."<a href=\"".HTTP_SERVER . "/index.php?option=com_oscommerce&osMod=product_info&products_id=" .$products[$i]['id']."\">".$products[$i]['name']."</a></li></ul>";
  }
}
$a['heading'] = HEADING_TITLE;
$a['heading_img'] = tep_image(DIR_WS_IMAGES . 'table_background_contact_us.gif', sprintf(HEADING_TITLE, $product_info['products_name']), HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT);

    $error = false;

    if (isset($_REQUEST['action']) && ($_REQUEST['action'] == 'process') && !tep_validate_email(trim($_REQUEST['friendemail']))) {
      $friendemail_error = true;
      $error = true;
    } else {
      $friendemail_error = false;
    }

    if (isset($_REQUEST['action']) && ($_REQUEST['action'] == 'process') && empty($_REQUEST['friendname'])) {
      $friendname_error = true;
      $error = true;
    } else {
      $friendname_error = false;
    }

    if (tep_session_is_registered('customer_id')) {
      $from_name = $account_values['customers_firstname'] . ' ' . $account_values['customers_lastname'];
      $from_email_address = $account_values['customers_email_address'];
    } else {
      $from_name = $_REQUEST['yourname'];
      $from_email_address = $_REQUEST['from'];
    }

    if (!tep_session_is_registered('customer_id')) {
      if (isset($_REQUEST['action']) && ($_REQUEST['action'] == 'process') && !tep_validate_email(trim($from_email_address))) {
        $fromemail_error = true;
        $error = true;
      } else {
        $fromemail_error = false;
      }
    }

    if (isset($_REQUEST['action']) && ($_REQUEST['action'] == 'process') && empty($from_name)) {
      $fromname_error = true;
      $error = true;
    } else {
      $fromname_error = false;
    }

    if (isset($_REQUEST['action']) && ($_REQUEST['action'] == 'process') && ($error == false)) {
      $email_subject = sprintf(TEXT_EMAIL_SUBJECT, $from_name, STORE_NAME);
	  $email_body = '<div style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; ">';
      $email_body.= sprintf(TEXT_EMAIL_INTRO, $_REQUEST['friendname'], $from_name, $_REQUEST['products_name'], STORE_NAME) . "\n\n";

      if (tep_not_null($_REQUEST['yourmessage'])) {
        $email_body .= TEXT_HERES_A_MESSAGE . $from_name.":\n";
		$email_body .= $_REQUEST['yourmessage'] . "\n\n";
      }

	  $email_body .= TEXT_EMAIL_ADDITIONAL.$wishliststring;

      $email_body .= sprintf(TEXT_EMAIL_SIGNATURE, STORE_NAME . "\n"). "<A HREF=\"".
  HTTP_SERVER ."\"><h3><i>".STORE_NAME."</A> "."\n";
                     "\n\n</div>";
//	  $email_body = nl2br($email_body);


      tep_mail($_REQUEST['friendname'], $_REQUEST['friendemail'], $email_subject, stripslashes($email_body), '', $from_email_address);
      $a['sentmail'] = sprintf(TEXT_EMAIL_SUCCESSFUL_SENT, $_REQUEST['friendemail']);
      $a['button_back'] = '<a href="' . tep_href_link(FILENAME_WISHLIST) . '">' . tep_image_button('button_back.gif', IMAGE_BUTTON_BACK) . '</a>';

    } else {
      if (tep_session_is_registered('customer_id')) {
        $your_name_prompt = $account_values['customers_firstname'] . ' ' . $account_values['customers_lastname'];
        $your_email_address_prompt = $account_values['customers_email_address'];
      } else {
        $your_name_prompt = tep_draw_input_field('yourname', (($fromname_error == true) ? $_REQUEST['yourname'] : $_REQUEST['yourname']));
        if ($fromname_error == true) $your_name_prompt .= '&nbsp;' . TEXT_REQUIRED;
        $your_email_address_prompt = tep_draw_input_field('from', (($fromemail_error == true) ? $_REQUEST['from'] : $_REQUEST['from']));
        if ($fromemail_error == true) $your_email_address_prompt .= ENTRY_EMAIL_ADDRESS_CHECK_ERROR;
      }
      $a['form'] = tep_draw_form('email_friend', tep_href_link(FILENAME_WISHLIST_SEND, 'action=process'));
      $a['cust_detail'] = FORM_TITLE_CUSTOMER_DETAILS;
      $a['cust_name'] = FORM_FIELD_CUSTOMER_NAME;
      $a['cust_name_input'] = $your_name_prompt; 
      $a['cust_email'] = FORM_FIELD_CUSTOMER_EMAIL;
      $a['cust_email_input'] = $your_email_address_prompt;
      $a['friend_detail'] = FORM_TITLE_FRIEND_DETAILS;
      $a['friend_name'] = FORM_FIELD_FRIEND_NAME;
      $a['friend_name_input'] = tep_draw_input_field('friendname', (($friendname_error == true) ? $_REQUEST['friendname'] : $_REQUEST['friendname'])); 
      if ($friendname_error == true) {
      $a['friend_name_input'] .=  '&nbsp;<b>' . TEXT_REQUIRED .'</b>';
      }
      $a['friend_email'] = FORM_FIELD_FRIEND_EMAIL;
      $a['friend_email_input'] = tep_draw_input_field('friendemail', (($friendemail_error == true) ? $_REQUEST['friendemail'] : $_REQUEST['send_to']));
      if ($friendemail_error == true) {
      $a['friend_email_input'] .= '&nbsp;<b>'. ENTRY_EMAIL_ADDRESS_CHECK_ERROR. '</b>';
      }
      $a['friend_message'] = FORM_TITLE_FRIEND_MESSAGE;
      $a['friend_message_input'] = tep_draw_textarea_field('yourmessage', 'soft', 40, 8);
      $a['button_back'] = '<a href="' . tep_href_link(FILENAME_WISHLIST) . '">' . tep_image_button('button_back.gif', IMAGE_BUTTON_BACK) . '</a>';
      $a['button_send'] = tep_image_submit('button_continue.gif', IMAGE_BUTTON_CONTINUE);

    }

require(WS_TEMPLATES . E_TEMPLATE_FOLDER . '/'.$osMod.'.html');
require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
<?php
  require(DIR_WS_INCLUDES . 'application_bottom.php');

  // -- webMS Modification --
  // reset the Mambo Database connection (stomped by osCommerce Connection)
  if (!DB_SHARED) {
    global $database, $mosConfig_host, $mosConfig_user, $mosConfig_password, $mosConfig_db, $mosConfig_dbprefix;
    $database = new database( $mosConfig_host, $mosConfig_user, $mosConfig_password, $mosConfig_db, $mosConfig_dbprefix );
  }
 ?>